package com.example.jvmdemo.org.fenixsoft.jvm.chapter2;

import java.util.ArrayList;
import java.util.List;

/**
 * VM Args：-Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError
 *
 * @author zzm
 */
public class HeapOOM {

    static class OOMObject {
    }

    public static void main(String[] args) {
        List<OOMObject> list = new ArrayList<>();
        int count=0;
        while (true) {
            count++;
            try {
                list.add(new OOMObject());
            }catch (Throwable throwable){
                System.out.println(count);
                System.out.println(list.size());
                break;
            }
        }
    }
}

